#!/usr/bin/env bash

DIR=$(realpath $0) && DIR=${DIR%/*}
cd $DIR
set -ex

if ! command -v modelscope &>/dev/null; then
  pip install modelscope
fi

mkdir -p model
modelscope download --model="Qwen/Qwen3-0.6B" --local_dir ./model/Qwen3-0.6B

if dpkg -l | grep -q 'nvidia-container-runtime'; then
  VERSION=$(dpkg -s nvidia-container-runtime | grep 'Version' | awk '{print $2}')
  echo "nvidia-container-runtime : $VERSION"
else
  curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
  curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list |
    sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' |
    sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

  sudo apt-get update
  sudo apt-get install -y nvidia-container-runtime
  sudo nvidia-ctk runtime configure --runtime=docker
  sudo systemctl restart docker

  sudo apt-get install -y nvidia-container-toolkit
fi
